<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>继承</title>
</head>
<body>
    <h1>继承</h1>
<script>
    class Parent{
        constructor(name,age){
            this.name=name;
            this.age=age;
        }
        say(){
            console.log(`姓名:${this.name}---年龄:${this.age}`);
        }
    }
    class Son extends Parent{
        constructor(name,age,hobby){
            super(name,age)//调用父类的构造函数
            this.hobby=hobby;
        }
        say(){
            console.log(`姓名:${this.name}---年龄:${this.age}----爱好:${this.hobby}`);
        }
    }
    let father=new Parent("小学生",10);
    father.say();//调用父类的方法

    let son=new Son("碰磕",20,'爱学习');
    son.say();//调用子类的方法
</script>
</body>
</html>